home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9917 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: uni-erlangen.de!winx03!sunshine!schoof
  2. From: schoof@informatik.uni-wuerzburg.de (Jochen Schoof)
  3. Newsgroups: comp.os.linux.help,comp.lang.c
  4. Subject: Re: strncpy bug?
  5. Followup-To: comp.os.linux.help,comp.lang.c
  6. Date: 14 Mar 1996 11:43:22 GMT
  7. Organization: University of Wuerzburg, Germany
  8. Message-ID: <4i90oq$a3a@winx03.informatik.uni-wuerzburg.de>
  9. References: <ccurtis.826776589@ee.fit.edu>
  10. NNTP-Posting-Host: wi2x01.informatik.uni-wuerzburg.de
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Christopher W. Curtis (ccurtis@ee.fit.edu) wrote:
  14. : I was wondering if this is a Linux thing (kernel 1.2.1) or a
  15. : more general 'problem'.  If you call strncpy as such:
  16. :     strncpy( dest, NULL, x );
  17. : it will seg fault.  Is this common among all platforms, or
  18. : just with Linux?
  19. :
  20. : The man page says nothing about it, but I would have presumed
  21. : that if str[n]cpy were passed NULL as a source, it would
  22. : merely catenate the destination.  Did I presume wrong?
  23.  
  24. My man page says:
  25.  
  26.        The  strcpy() function copies the string pointed to be src
  27.        (including the terminating `\0' character)  to  the  array
  28.        pointed  to by dest.  The strings may not overlap, and the
  29.        destination string dest must be large  enough  to  receive
  30.        the copy.
  31.  
  32.        The  strncpy()  function  is similar, except that only the
  33.        first n bytes of src are copied.
  34.  
  35. When passing NULL as the src pointer, it definetly does not reference
  36. a string. Therefore NULL is not a legal parameter to strcpy() and
  37. strncpy(). Your expectation of what should happen is true for the
  38. empty string (i.e. ""), but this is completely different from NULL.
  39.  
  40. - Jochen
  41.  
  42. --
  43. --------------------------------------------------------------------------
  44.  Jochen Schoof                  mailto:schoof@informatik.uni-wuerzburg.de
  45.  Lehrstuhl fuer Informatik II +-------------------------------------------
  46.  Universitaet Wuerzburg       | You are just reading a .sig-light:
  47.  D-97074 Wuerzburg (Germany)  | It is free of fat, sugar and cholesterol!
  48. ------------------------------+-------------------------------------------
  49.  WWW-Homepage:        http://www.informatik.uni-wuerzburg.de/staff/joscho
  50. --------------------------------------------------------------------------
  51.